<?php

namespace think\seecms;

use seecms\See;
use think\seecms\command\Database;
use think\seecms\command\Publish;
use think\Route;
use think\Service;

class SeeService extends Service
{
    public function register()
    {

    }

    public function boot(Route $route): void
    {
        // 设置配置文件
        $config = config('seecms');
        See::config()->set($config);

        //设置语言包
        $support = See::config()->lang->support();
        $cookie_var = See::config()->lang->cookieVar();

        if ($cookie_var) {
            $lang = cookie($cookie_var, '');
        } else {
            $header_var = See::config()->lang->headerVar();
            $lang = $header_var ? $this->app->request->header($header_var) : '';
        }

        if (empty($lang) || empty($support[$lang] ?? '')) {
            $lang = 'zh-cn';
        }

        See::lang()->switchLangSet($lang);

        // 添加命令
        $this->commands(
            [
                'see:publish' => Publish::class,
                'see:database' => Database::class,
            ]
        );
    }
}